#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    string reverseWords(string s) 
    {
        int begin = 0;
        int size = s.size();
        while (begin < size)
        {
            int pos = s.find(' ',begin);
            if (pos == string::npos)break;
            reverse(s.begin() + begin, s.begin() + pos );
            begin = pos+1;
        }
        reverse(s.begin() + begin, s.end());
        return s;
    }
};

